#pragma once

#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavfilter/buffersink.h>
#include <libavfilter/buffersrc.h>
#include <libavutil/opt.h>
#include <libavutil/log.h>
#ifdef __cplusplus
}
#endif

#include <string>

class InputStream
{
    public:
        static const int avloglevel = AV_LOG_INFO;
    public:
        InputStream();  
        ~InputStream();
        bool open_url(const char* url);//rtsp ; rtmp ;local file; 
        void close();
        bool has_audio();
        bool has_video();
        int read_stream(AVPacket* packet);  
        bool is_audio(AVPacket* packet);
        bool is_video(AVPacket* packet);

        int get_video_stream_info(AVCodecParameters* AVCodecParameters, AVRational& time_base,int& index);
        int get_audio_stream_info(AVCodecParameters* AVCodecParameters, AVRational& time_base,int& index);     
        //bool open_success();
    private:
        std::string m_url;
        bool m_open_success =false;
        AVFormatContext *m_fmt_ctx = nullptr;
        bool m_has_audio;
        int m_video_stream_index = -1;
        int m_audio_stream_index = -1;

        AVStream*  m_video_stream = nullptr;
        AVStream*  m_audio_stream = nullptr;

        bool m_had_key_video_frame = false;
};